local sw,sh=guiGetScreenSize()
local gsize=sw>800 and 32 or 16


addEventHandler("onClientMinimize",root,
function()
	setElementData(localPlayer,"AFK",true)
end
)

addEventHandler("onClientRestore",root,
function()
	setElementData(localPlayer,"AFK",false)
end
)


local sw,sh = guiGetScreenSize()
local px,py = sw/1366,sh/768
font = dxCreateFont( ":cmta-pobieraniezasobow/OSB.ttf", 10.5*px )


addEventHandler("onClientRender", root, function()
  local rootx, rooty, rootz = getCameraMatrix()
        for i, vehicle in ipairs(getElementsByType("vehicle", root, true)) do
            local opis=getElementData(vehicle,"opis")
            if (opis) then
            local x,y,z=getElementPosition(vehicle)
            local distance = getDistanceBetweenPoints3D(rootx, rooty, rootz, x, y, z)
            local kierowca=getVehicleController(vehicle)
            if (distance<=15 or (kierowca and kierowca==localPlayer)) then
                local sx,sy = getScreenFromWorldPosition(x,y,z, 200)
                if (sx and sy) then
                    dxDrawText(opis, sx-(sw/5),sy,sx+(sw/5),sy, tocolor(255,255,255,155), 1.0, "default-small", "center","center",false,true)
                end
            end
            end
        end
        
        local ctrl=getKeyState("i")

        for i, player in ipairs(getElementsByType("player",root,true)) do
              --   if player == localPlayer then return end        
                if player ~= localPlayer then
                local x,y,z = getPedBonePosition(player,8)
                local sx, sy = getScreenFromWorldPosition(x, y, z+0.5)
                if sx then
						local distance = getDistanceBetweenPoints3D(rootx, rooty, rootz, x, y, z)
                        local fX = math.floor(sx)
                        local fY = math.floor(sy)

                        local alpha = 120
                        
                        if(distance <= 35) then
                         --   if (ctrl) == true and not isChatBoxInputActive() and not isConsoleActive() then
                         --       exports["PSSM-gui"]:createCustomText2("#ff0000poziom ["..getElementData(player, "player:lvl").."]\nczas online: "..getElementData(player,"player:przegranyczas").." min\nKanał głosowy: ["..getElementData(player,"player:kanal").."]", fX, fY+30, fX, fY+30, tocolor(255, 255, 255, 255), 1, "font19.1", "center", "center", false, false, false, false, false)
                          --  end
							local level = tonumber(getElementData(player, "player:level"))
							local premium = getElementData(player,"player:premium")
							local vip = getElementData(player,"player:vip")
							local lvl = getElementData(player,"player:lvl")
                            local mute = getElementData(player,"gracz:mute",true)
                            local sponsor = getElementData(player,"player:sponsor")
                            local inv = getElementData(player,"player:inv")
                            if level == 1 then idcolor="#00CC00" elseif level == 2 then idcolor="#006699" elseif level == 3 then idcolor="#ff0000" elseif level == 4 then idcolor="#a31303" elseif level == 5 then idcolor="#a31303" elseif vip then idcolor="#d97319" elseif premium then idcolor="#D9D919" else idcolor="#FFFFFF" end
                            if not inv then
                            dxDrawText("#FFFFFF["..idcolor..""..getElementData(player, "id").."#FFFFFF] #FFFFFF"..getPlayerName(player):gsub("#%x%x%x%x%x%x","").."", fX, fY, fX, fY, tocolor(255, 255, 255, 255), 1, font, "center", "center", false, false, false, true, false)
                        end
                           --[[
                            if getElementData(player,"player:np") and not inv then
                            exports["PSSM-gui"]:createCustomText2("#FFFFFF#FFFFFF#a31303* Gracz nieprzytomny *#FFFFFF", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, size or "font19", "center", "center", false, false, false, false, false)
                            elseif getElementData(player,"AFK") and not inv then
                            exports["PSSM-gui"]:createCustomText2("#FFFFFF#FFFFFF#a31303Gra zminimalizowana#FFFFFF", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, "font20" or "font19", "center", "center", false, false, false, false, false)
                            elseif level == 1 and not inv then
                            exports["PSSM-gui"]:createCustomText2("#00CC00Support", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, size or "font19", "center", "center", false, false, false, false, false)
                            elseif level == 2 and not inv then
                            exports["PSSM-gui"]:createCustomText2("#006699Moderator", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, size or "font19", "center", "center", false, false, false, false, false)
                            elseif level == 3 and not inv then
                            exports["PSSM-gui"]:createCustomText2("#ff0000Administrator", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, size or "font19", "center", "center", false, false, false, false, false)
                            elseif level == 4 and not inv then
                            exports["PSSM-gui"]:createCustomText2("#cc0000RCON", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, size or "font19", "center", "center", false, false, false, false, false)
                            elseif level == 5 and not inv then
                            exports["PSSM-gui"]:createCustomText2("#00FA9A✫ Manager ✫", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, size or "font19", "center", "center", false, false, false, false, false)
                            elseif mute and not inv then
                            exports["PSSM-gui"]:createCustomText2("#a31303Wyciszony", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, size or "font19", "center", "center", false, false, false, false, false)
                            elseif vip and not inv then
                            exports["PSSM-gui"]:createCustomText2("#d97319V.I.P", fX, fY-16, fX, fY-16, tocolor(255, 255, 255, 255), 1, size or "font19", "center", "center", false, false, false, false, false)
                            end]]
                        end
                 end   
         end
        end    
end)

